# -*- coding: utf-8 -*-
# author:yang  time:19-8-9 上午8:53

import re
import itertools


def address(addr):
    id_list = [int(x) for x in addr.split('.')]
    print(id_list)
    str_addr_new = ''
    for i in id_list:
        id_bin = bin(i)
        str_addr = re.sub(r'0b', '', str(id_bin))
        str_addr_new = str_addr_new + str_addr.zfill(8)
    print(str_addr_new)
    print(int(str_addr_new, 2))
    return str_addr_new, int(str_addr_new, 2)


f = address("127.0.0.1")
print(f)
print('*'*50)

v = dict.fromkeys(['k1', 'k2'], [])
print(v)
print(v['k1'])
v['k1'].append(666)
print(v)
v['k1'] = 777
print(v)
print('*'*50)

x = dict.fromkeys(['k1', 'k2'], [666])
print(x)

print('*'*50)

print(len(list(itertools.permutations('12345', 3))))
str_list = list(itertools.permutations('12345', 3))
str_list_new = []
for i in str_list:
    type_to_str = ''
    for j in i:
        type_to_str += j
    str_list_new.append(int(type_to_str))

print(str_list_new)


def login_type(type):
    def quter(f):
        if type == 'QQ':
            name = input('请输入用户名：')
            psw = input('请输入密码：')
            if name == 's' and psw == '198765':
                print('登陆成功！')
                return f()
            else:
                print('登录失败，请正确输入！')
        else:
            print('请使用QQ登录！')

    return quter


type_login = input('请输入登录方式:')


@login_type(type_login)
def america():
    print('美国人')


@login_type(type_login)
def japan():
    print('日本人')


america()

japan()
